package cn.edu.scau.cmi.liuxintong;
import java.awt.event.ActionEvent;
import java.util.ArrayList;

import cn.edu.scau.cmi.liuxintong.adapter.Student;
import cn.edu.scau.cmi.liuxintong.adapter.objectAdapter;
import cn.edu.scau.cmi.liuxintong.factory.BeefMeatFactory;
import cn.edu.scau.cmi.liuxintong.factory.ChickenMeatFactory;
import cn.edu.scau.cmi.liuxintong.factory.PorkMeatFactory;
import javafx.application.*;
import javafx.beans.value.ChangeListener;
import javafx.collections.FXCollections;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.stage.*;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.scene.web.HTMLEditor;
public class objectAdapterClient extends Application {
	public void start(Stage primaryStage) throws Exception {
		 AnchorPane anchorPane = new AnchorPane();
		 objectAdapter objectadapter=new objectAdapter();
		 Label label1 = new Label("请输入学生名称:");
		 Label label2=new Label("请输入学生学号：");
		 TextField textField1 = new TextField();
		 TextField textField2 = new TextField();
		 Button button = new Button("创建");
		 TextArea textArea = new TextArea();
	        textArea.setPrefHeight(380);
	        textArea.setPrefWidth(680);
		 anchorPane.getChildren().addAll(label1,label2,textField1,textField2,button,textArea);
		 button.setOnAction(new EventHandler() {
				public void handle(Event event) {
				Student student=new Student();
				student.setName(textField1.getText());
				student.setId(Integer.parseInt(textField2.getText()));
				objectadapter.insertStudent(student);
				ArrayList<Student> students=new ArrayList<Student>();
				students=objectadapter.getStudents();
				textArea.appendText("现在已有的学生名单为：\n");
				for(int i=0;i<students.size();i++)
				 textArea.appendText(students.get(i).getId()+"      "+students.get(i).getName()+"\n");
				}
				
			});
		//界面布局
		 AnchorPane.setLeftAnchor(label1, 10.0);
		 AnchorPane.setBottomAnchor(label1,480.0);//下
		 AnchorPane.setLeftAnchor(textField1, 140.0);
		 AnchorPane.setBottomAnchor(textField1,470.0);//下
		 AnchorPane.setLeftAnchor(label2, 10.0);
		 AnchorPane.setBottomAnchor(label2,400.0);//下
		 AnchorPane.setLeftAnchor(textField2, 140.0);
		 AnchorPane.setBottomAnchor(textField2,400.0);//下
		 AnchorPane.setLeftAnchor(button,350.0);
		 AnchorPane.setBottomAnchor(button,400.0);//下
		 AnchorPane.setLeftAnchor(textArea, 10.0);
		 AnchorPane.setBottomAnchor(textArea,10.0);
		 primaryStage.setScene(new Scene(anchorPane, 700, 500));
	        primaryStage.show();
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		 launch(args);
	}
}
